package tom.jiafei;
import java.sql.*;
import java.io.*;
public class InsertBook{
	String bookid="sss",bookname,ISBN,author,price,filedir,type;
	public void setUserid(String str){
		bookid=str;
	}
	public String getUserid(){
		return bookid;
	}
	public void setUname(String str){
		try{
			byte b[]=str.getBytes("ISO-8859-1");
            bookname=new String(b);}
        catch(Exception e){}
	}
	public String getUname(){
		return bookname;
	}
	public void setPassward(String str){
		ISBN=str;
	}
	public String getPassward(){
		return ISBN;
	}
	public void setTell(String str){
		author=str;
	}
	public String getTell(){
		return author;
	}
	public void setAddress(String str){
		try{
			byte b[]=str.getBytes("ISO-8859-1");
            price=new String(b);}
        catch(Exception e){}
	}
	public String getAddress(){
		return price;
	}
	public void setRealName(String str){
		try{
			byte b[]=str.getBytes("ISO-8859-1");
            filedir=new String(b);}
        catch(Exception e){}
	}
	public String getRealName(){
		return filedir;
	}
	public void setEmail(String str){
		type=str;
	}
	public String getEmail(){
		return type;
	}
	public boolean getInsert(){
		boolean  insert=false;
		String insertCondition="insert into book values('"+bookid+"','"+bookname+"','"+ISBN+"','"+author+"','"+price+"','"+filedir+"','"+type+"')";
		Connection con;
	    Statement sql;
	    try{
	    	Class.forName("com.mysql.jdbc.Driver");
	    	}
	    catch(Exception e){}
   
    try{
		String uri = "jdbc:mysql://127.0.0.1:3306/book_store?useUnicode=true&characterEncoding=utf8";
		String user = "root";
		String password = "1e916d4e2405be9e";
		con=DriverManager.getConnection(uri,user,password);
		sql=con.createStatement();
		int m=sql.executeUpdate(insertCondition);
		if(m!=0){
			insert=true;			
		}
		con.close();
	}
	catch(SQLException e1){insert=false;}
	return insert;
	}
}